<?php

class TrongngayController extends Controller
{
    public function filter(){
        return array(
        'accessControl',
        );
    }
    public function accessRules(){
        return array(
        array('deny',
        'actions'=>array('index', 'truyenthong'),
        'users'=>array('*'),
        ),
        
        );
    } 
    //public $layout = "column_admin";
    public function actionIndex(){
        $this->actionTruyenthong();
    }
    public function actionTruyenthong(){
        $row = array();  
        $date = date("Y-m-d",time());
        $row = AdminKqMienbac::getRowByDate($date);
        $this->render('truyenthong',array("row"=>$row)); 
    }
    public function actionSaveDacbiet(){
        $user = Yii::app()->user->name;
        $giai_dacbiet   = isset($_POST["giai_dacbiet"])     ? $_POST["giai_dacbiet"]:"";  
        $ngay_quay      = isset($_POST["ngay_quay"])        ? $_POST["ngay_quay"]:"";

        //echo $ngay_quay;die;
        $boso1 = substr($giai_dacbiet,strlen($giai_dacbiet)-2,2);

        $row = AdminKqMienbac::getIdByDate($ngay_quay);
        if(!$row){
            $last_id = AdminKqMienbac::insertDacBiet($giai_dacbiet,$ngay_quay,$user);    
                    
        }else{
            $result = AdminKqMienbac::updateDacBiet($row["id"],$giai_dacbiet,$user);
            $last_id = $row["id"];
        }
           
        $row_update = AdminKqMienbac::getRowById($last_id);    
        
        /*Lỗi set cache*/
        /*$this->setCacheMienBac($row_update);*/   
        /*if($boso1 != 0 && $boso1 !="" ){
        $last_boso_id = AdminKqMienbac::insertThongke($last_id,$boso1,$ngay_quay,"GDB",$user);
        }*/
        
        /*$cacheService = new CacheService("KqMienbac","getRowByDate","");
        $dependency = $cacheService->createDependency();
        Yii::app ()->setGlobalState ( $dependency, time () );
        $cacheService = new CacheService("KqMienbac","getRowByDate",$ngay_quay);
        $dependency = $cacheService->createDependency();
        Yii::app ()->setGlobalState ( $dependency, time () ); */
           
        if($last_id !=0){
            echo 1;
        }else{
            echo 0;
        }
    }
    public function actionSaveGiainhat(){
        $user = Yii::app()->user->name;
        $giai_nhat  = isset($_POST["giai_nhat"])    ? $_POST["giai_nhat"]   :"";  
        $ngay_quay  = isset($_POST["ngay_quay"])    ? $_POST["ngay_quay"]   :"";

        $boso1 = substr($giai_nhat,strlen($giai_nhat)-2,2);

        $row = AdminKqMienbac::model()->getIdByDate($ngay_quay);

        if(!$row){
            $last_id = AdminKqMienbac::insertGiaiNhat($giai_nhat,$ngay_quay,$user);            
        }else{
            $result = AdminKqMienbac::updateGiaiNhat($row["id"],$giai_nhat,$user);
            $last_id = $row["id"];
        }
        $row_update = AdminKqMienbac::getRowById($last_id);
        /*$this->setCacheMienBac($row_update);*/
        /*if($boso1 != 0 && $boso1 !="" ){
        $last_boso_id = AdminKqMienbac::insertThongke($last_id,$boso1,$ngay_quay,"G1",$user);
        }*/

        /*$cacheService = new CacheService("KqMienbac","getRowByDate","");
        $dependency = $cacheService->createDependency();
        Yii::app ()->setGlobalState ( $dependency, time () );
        $cacheService = new CacheService("KqMienbac","getRowByDate",$ngay_quay);
        $dependency = $cacheService->createDependency();
        Yii::app ()->setGlobalState ( $dependency, time () );*/
        if($last_id !=0){
            echo 1;
        }else{
            echo 0;
        }
    }
    public function actionSaveGiainhi(){
        $user = Yii::app()->user->name;
        $giai_nhi_1     = isset($_POST["giai_nhi_1"])   ? $_POST["giai_nhi_1"]:"";
        $giai_nhi_2     = isset($_POST["giai_nhi_2"])   ? $_POST["giai_nhi_2"]:"";       
        $ngay_quay      = isset($_POST["ngay_quay"])    ? $_POST["ngay_quay"]:"";

        $boso1 = substr($giai_nhi_1,strlen($giai_nhi_1)-2,2);
        $boso2 = substr($giai_nhi_2,strlen($giai_nhi_2)-2,2);

        $row = AdminKqMienbac::model()->getIdByDate($ngay_quay);
        if(!$row){
            $last_id = AdminKqMienbac::insertGiaiNhi($giai_nhi_1,$giai_nhi_2,$ngay_quay,$user);            
        }else{
            $result = AdminKqMienbac::updateGiaiNhi($row["id"],$giai_nhi_1,$giai_nhi_2,$user);
            $last_id = $row["id"];
        }
        $row_update = AdminKqMienbac::getRowById($last_id);
        /*$this->setCacheMienBac($row_update);*/
        /*if($boso1 != 0 && $boso1 !="" ){
        $last_boso_id = AdminKqMienbac::insertThongke($last_id,$boso1,$ngay_quay,"G21",$user);
        }
        if($boso2 != 0 && $boso2 !="" ){
        $last_boso_id = AdminKqMienbac::insertThongke($last_id,$boso2,$ngay_quay,"G22",$user);
        } */

        /*$cacheService = new CacheService("KqMienbac","getRowByDate","");
        $dependency = $cacheService->createDependency();
        Yii::app ()->setGlobalState ( $dependency, time () );
        $cacheService = new CacheService("KqMienbac","getRowByDate",$ngay_quay);
        $dependency = $cacheService->createDependency();
        Yii::app ()->setGlobalState ( $dependency, time () );*/
        if($last_id !=0){
            echo 1;
        }else{
            echo 0;
        }
    }
    public function actionSaveGiaiba(){
        $user = Yii::app()->user->name;
        $giai_ba_1 = isset($_POST["giai_ba_1"]) ? $_POST["giai_ba_1"]:"";
        $giai_ba_2 = isset($_POST["giai_ba_2"]) ? $_POST["giai_ba_2"]:"";
        $giai_ba_3 = isset($_POST["giai_ba_3"]) ? $_POST["giai_ba_3"]:"";
        $giai_ba_4 = isset($_POST["giai_ba_4"]) ? $_POST["giai_ba_4"]:"";
        $giai_ba_5 = isset($_POST["giai_ba_5"]) ? $_POST["giai_ba_5"]:"";
        $giai_ba_6 = isset($_POST["giai_ba_6"]) ? $_POST["giai_ba_6"]:"";        
        $ngay_quay = isset($_POST["ngay_quay"]) ? $_POST["ngay_quay"]:"";

        $boso1 = substr($giai_ba_1,strlen($giai_ba_1)-2,2);
        $boso2 = substr($giai_ba_2,strlen($giai_ba_2)-2,2);
        $boso3 = substr($giai_ba_3,strlen($giai_ba_3)-2,2);
        $boso4 = substr($giai_ba_4,strlen($giai_ba_4)-2,2);
        $boso5 = substr($giai_ba_5,strlen($giai_ba_5)-2,2);
        $boso6 = substr($giai_ba_6,strlen($giai_ba_6)-2,2);

        $row = AdminKqMienbac::model()->getIdByDate($ngay_quay);
        if(!$row){
            $last_id = AdminKqMienbac::insertGiaiBa($giai_ba_1,$giai_ba_2,$giai_ba_3,$giai_ba_4,$giai_ba_5,$giai_ba_6,$ngay_quay,$user);            
        }else{
            $result = AdminKqMienbac::updateGiaiBa($row["id"],$giai_ba_1,$giai_ba_2,$giai_ba_3,$giai_ba_4,$giai_ba_5,$giai_ba_6,$user);
            $last_id = $row["id"];
        }
        $row_update = AdminKqMienbac::getRowById($last_id);
        /*$this->setCacheMienBac($row_update);*/
        /*if($boso1 != 0 && $boso1 !="" ){

        $last_boso_id = AdminKqMienbac::insertThongke($last_id,$boso1,$ngay_quay,"G31",$user);

        }

        if($boso2 != 0 && $boso2 !="" ){

        $last_boso_id = AdminKqMienbac::insertThongke($last_id,$boso2,$ngay_quay,"G32",$user);

        }
        if($boso3 != 0 && $boso3 !="" ){

        $last_boso_id = AdminKqMienbac::insertThongke($last_id,$boso3,$ngay_quay,"G33",$user);

        }
        if($boso4 != 0 && $boso4 !="" ){

        $last_boso_id = AdminKqMienbac::insertThongke($last_id,$boso4,$ngay_quay,"G34",$user);

        }
        if($boso5 != 0 && $boso5 !="" ){

        $last_boso_id = AdminKqMienbac::insertThongke($last_id,$boso5,$ngay_quay,"G35",$user);

        }
        if($boso6 != 0 && $boso6 !="" ){

        $last_boso_id = AdminKqMienbac::insertThongke($last_id,$boso6,$ngay_quay,"G36",$user);

        } */
        /*$cacheService = new CacheService("KqMienbac","getRowByDate","");
        $dependency = $cacheService->createDependency();
        Yii::app ()->setGlobalState ( $dependency, time () );
        $cacheService = new CacheService("KqMienbac","getRowByDate",$ngay_quay);
        $dependency = $cacheService->createDependency();
        Yii::app ()->setGlobalState ( $dependency, time () ); */
        //echo $last_id ;die; 
        if($last_id !=0){
            echo 1;
        }else{
            echo 0;
        }
    }
    public function actionSaveGiaitu(){
        $user = Yii::app()->user->name;
        $giai_tu_1 = isset($_POST["giai_tu_1"]) ? $_POST["giai_tu_1"]:"";
        $giai_tu_2 = isset($_POST["giai_tu_2"]) ? $_POST["giai_tu_2"]:"";
        $giai_tu_3 = isset($_POST["giai_tu_3"]) ? $_POST["giai_tu_3"]:"";
        $giai_tu_4 = isset($_POST["giai_tu_4"]) ? $_POST["giai_tu_4"]:"";       
        $ngay_quay = isset($_POST["ngay_quay"]) ? $_POST["ngay_quay"]:"";

        $boso1 = substr($giai_tu_1,strlen($giai_tu_1)-2,2);
        $boso2 = substr($giai_tu_2,strlen($giai_tu_2)-2,2);
        $boso3 = substr($giai_tu_3,strlen($giai_tu_3)-2,2);
        $boso4 = substr($giai_tu_4,strlen($giai_tu_4)-2,2);

        $row = AdminKqMienbac::getIdByDate($ngay_quay);
        if(!$row){
            $last_id = AdminKqMienbac::insertGiaiTu($giai_tu_1,$giai_tu_2,$giai_tu_3,$giai_tu_4,$ngay_quay,$user);            
        }else{
            $result = AdminKqMienbac::updateGiaiTu($row["id"],$giai_tu_1,$giai_tu_2,$giai_tu_3,$giai_tu_4,$user);
            $last_id = $row["id"];
        }
        $row_update = AdminKqMienbac::getRowById($last_id);
        /*$this->setCacheMienBac($row_update); */
        /*if($boso1 != 0 && $boso1 !="" ){

        $last_boso_id = AdminKqMienbac::insertThongke($last_id,$boso1,$ngay_quay,"G41",$user);

        }
        if($boso2 != 0 && $boso2 !="" ){

        $last_boso_id = AdminKqMienbac::insertThongke($last_id,$boso2,$ngay_quay,"G42",$user);

        }
        if($boso3 != 0 && $boso3 !="" ){

        $last_boso_id = AdminKqMienbac::insertThongke($last_id,$boso3,$ngay_quay,"G43",$user);

        }
        if($boso4 != 0 && $boso4 !="" ){

        $last_boso_id = AdminKqMienbac::insertThongke($last_id,$boso4,$ngay_quay,"G44",$user);

        }*/
        /*$cacheService = new CacheService("KqMienbac","getRowByDate","");
        $dependency = $cacheService->createDependency();
        Yii::app ()->setGlobalState ( $dependency, time () );
        $cacheService = new CacheService("KqMienbac","getRowByDate",$ngay_quay);
        $dependency = $cacheService->createDependency();
        Yii::app ()->setGlobalState ( $dependency, time () );*/
        //echo $last_id ;die; 
        if($last_id !=0){
            echo 1;
        }else{
            echo 0;
        }
    }
    public function actionSaveGiainam(){

        $user = Yii::app()->user->name;
        $giai_nam_1 = isset($_POST["giai_nam_1"]) ? $_POST["giai_nam_1"]:"";
        $giai_nam_2 = isset($_POST["giai_nam_2"]) ? $_POST["giai_nam_2"]:"";
        $giai_nam_3 = isset($_POST["giai_nam_3"]) ? $_POST["giai_nam_3"]:"";
        $giai_nam_4 = isset($_POST["giai_nam_4"]) ? $_POST["giai_nam_4"]:"";
        $giai_nam_5 = isset($_POST["giai_nam_5"]) ? $_POST["giai_nam_5"]:"";
        $giai_nam_6 = isset($_POST["giai_nam_6"]) ? $_POST["giai_nam_6"]:"";        
        $ngay_quay = isset($_POST["ngay_quay"]) ? $_POST["ngay_quay"]:"";

        $boso1 = substr($giai_nam_1,strlen($giai_nam_1)-2,2);
        $boso2 = substr($giai_nam_2,strlen($giai_nam_2)-2,2);
        $boso3 = substr($giai_nam_3,strlen($giai_nam_3)-2,2);
        $boso4 = substr($giai_nam_4,strlen($giai_nam_4)-2,2);
        $boso5 = substr($giai_nam_5,strlen($giai_nam_5)-2,2);
        $boso6 = substr($giai_nam_6,strlen($giai_nam_6)-2,2);
        $row = AdminKqMienbac::model()->getIdByDate($ngay_quay);
        if(!$row){
            $last_id = AdminKqMienbac::insertGiaiNam($giai_nam_1,$giai_nam_2,$giai_nam_3,$giai_nam_4,$giai_nam_5,$giai_nam_6,$ngay_quay,$user);            
        }else{
            $result = AdminKqMienbac::updateGiaiNam($row["id"],$giai_nam_1,$giai_nam_2,$giai_nam_3,$giai_nam_4,$giai_nam_5,$giai_nam_6,$user);
            $last_id = $row["id"];
        }
        $row_update = AdminKqMienbac::getRowById($last_id);
        /*$this->setCacheMienBac($row_update);*/
        /*if($boso1 !=0 && $boso1 !=""){

        $last_boso_id = AdminKqMienbac::insertThongke($last_id,$boso1,$ngay_quay,"G51",$user);

        }
        if($boso2 !=0 && $boso2 !=""){

        $last_boso_id = AdminKqMienbac::insertThongke($last_id,$boso2,$ngay_quay,"G52",$user);

        }
        if($boso3 !=0 && $boso3 !=""){

        $last_boso_id = AdminKqMienbac::insertThongke($last_id,$boso3,$ngay_quay,"G53",$user);
        }
        if($boso4 !=0 && $boso4 !=""){

        $last_boso_id = AdminKqMienbac::insertThongke($last_id,$boso4,$ngay_quay,"G54",$user);

        }
        if($boso5 !=0 && $boso5 !=""){

        $last_boso_id = AdminKqMienbac::insertThongke($last_id,$boso5,$ngay_quay,"G55",$user);

        }
        if($boso6 !=0 && $boso6 !=""){

        $last_boso_id = AdminKqMienbac::insertThongke($last_id,$boso6,$ngay_quay,"G56",$user);

        }*/

        /*$cacheService = new CacheService("KqMienbac","getRowByDate","");
        $dependency = $cacheService->createDependency();
        Yii::app ()->setGlobalState ( $dependency, time () );
        $cacheService = new CacheService("KqMienbac","getRowByDate",$ngay_quay);
        $dependency = $cacheService->createDependency();
        Yii::app ()->setGlobalState ( $dependency, time () );*/
        //echo $last_id ;die; 
        if($last_id !=0){
            echo 1;
        }else{
            echo 0;
        }
    }
    public function actionSaveGiaisau(){
        $user = Yii::app()->user->name;
        $giai_sau_1 = isset($_POST["giai_sau_1"]) ? $_POST["giai_sau_1"]:"";
        $giai_sau_2 = isset($_POST["giai_sau_2"]) ? $_POST["giai_sau_2"]:"";
        $giai_sau_3 = isset($_POST["giai_sau_3"]) ? $_POST["giai_sau_3"]:"";
        $ngay_quay = isset($_POST["ngay_quay"]) ? $_POST["ngay_quay"]:"";
        
        $boso1 = substr($giai_sau_1,strlen($giai_sau_1)-2,2);
        $boso2 = substr($giai_sau_2,strlen($giai_sau_2)-2,2);
        $boso3 = substr($giai_sau_3,strlen($giai_sau_3)-2,2);

        $row = AdminKqMienbac::model()->getIdByDate($ngay_quay);
        if(!$row){
            $last_id = AdminKqMienbac::insertGiaiSau($giai_sau_1,$giai_sau_2,$giai_sau_3,$ngay_quay,$user);            
        }else{
            $result = AdminKqMienbac::updateGiaiSau($row["id"],$giai_sau_1,$giai_sau_2,$giai_sau_3,$user);
            $last_id = $row["id"];
        }
        $row_update = AdminKqMienbac::getRowById($last_id);
        /*$this->setCacheMienBac($row_update);*/
        /*if($boso1 !=0 && $boso1 !=""){

        $last_boso_id = AdminKqMienbac::insertThongke($last_id,$boso1,$ngay_quay,"G61",$user);

        }
        if($boso2 !=0 && $boso2 !=""){

        $last_boso_id = AdminKqMienbac::insertThongke($last_id,$boso2,$ngay_quay,"G62",$user);

        }
        if($boso3 !=0 && $boso3 !=""){

        $last_boso_id = AdminKqMienbac::insertThongke($last_id,$boso3,$ngay_quay,"G63",$user);

        }*/

        /*$cacheService = new CacheService("KqMienbac","getRowByDate","");
        $dependency = $cacheService->createDependency();
        Yii::app ()->setGlobalState ( $dependency, time () );
        $cacheService = new CacheService("KqMienbac","getRowByDate",$ngay_quay);
        $dependency = $cacheService->createDependency();
        Yii::app ()->setGlobalState ( $dependency, time () );*/
        //echo $last_id ;die; 
        if($last_id !=0){
            echo 1;
        }else{
            echo 0;
        }
    }
    public function actionSaveGiaibay(){
        $user = Yii::app()->user->name;
        $giai_bay_1 = isset($_POST["giai_bay_1"]) ? $_POST["giai_bay_1"]:"";
        $giai_bay_2 = isset($_POST["giai_bay_2"]) ? $_POST["giai_bay_2"]:"";
        $giai_bay_3 = isset($_POST["giai_bay_3"]) ? $_POST["giai_bay_3"]:"";
        $giai_bay_4 = isset($_POST["giai_bay_4"]) ? $_POST["giai_bay_4"]:"";
        $ngay_quay = isset($_POST["ngay_quay"]) ? $_POST["ngay_quay"]:"";

        $boso1 = substr($giai_bay_1,strlen($giai_bay_1)-2,2);
        $boso2 = substr($giai_bay_2,strlen($giai_bay_2)-2,2);
        $boso3 = substr($giai_bay_3,strlen($giai_bay_3)-2,2);
        $boso4 = substr($giai_bay_4,strlen($giai_bay_4)-2,2);

        $row = AdminKqMienbac::model()->getIdByDate($ngay_quay);
        if(!$row){

            $last_id = AdminKqMienbac::insertGiaiBay($giai_bay_1,$giai_bay_2,$giai_bay_3,$giai_bay_4,$ngay_quay,$user);            
        }else{
            $result = AdminKqMienbac::updateGiaiBay($row["id"],$giai_bay_1,$giai_bay_2,$giai_bay_3,$giai_bay_4,$user);
            $last_id = $row["id"];
        }
        $row_update = AdminKqMienbac::getRowById($last_id);
        /*$this->setCacheMienBac($row_update);*/
        /*if($boso1 !=0 && $boso1 !=""){

        $last_boso_id = AdminKqMienbac::insertThongke($last_id,$boso1,$ngay_quay,"G71",$user);

        }
        if($boso2 !=0 && $boso2 !=""){

        $last_boso_id = AdminKqMienbac::insertThongke($last_id,$boso2,$ngay_quay,"G72",$user);

        }
        if($boso3 !=0 && $boso3 !=""){

        $last_boso_id = AdminKqMienbac::insertThongke($last_id,$boso3,$ngay_quay,"G73",$user);

        }
        if($boso4 !=0 && $boso4 !=""){

        $last_boso_id = AdminKqMienbac::insertThongke($last_id,$boso4,$ngay_quay,"G74",$user);

        }*/

        /*$cacheService = new CacheService("KqMienbac","getRowByDate","");
        $dependency = $cacheService->createDependency();
        Yii::app ()->setGlobalState ( $dependency, time () );
        $cacheService = new CacheService("KqMienbac","getRowByDate",$ngay_quay);
        $dependency = $cacheService->createDependency();
        Yii::app ()->setGlobalState ( $dependency, time () ); */
        if($last_id !=0){
            echo 1;
        }else{
            echo 0;
        }
    }


    public function actionMiennam(){
        $row = array();
        $date = date("Y-m-d",time()); 
        $day = getdate(time());
        $wday = $day["wday"]; 
        $day_of_week = StringUtils::getDayVi($wday);  
        $mien_nam = ConstantsUtil::MIEN_NAM; 
        $rowProvince = AdminProvince::getRowsByDateAndRegion($mien_nam,$day_of_week);
        for($i=0;$i<count($rowProvince);$i++){

            $rows[$i] = AdminKqMiennam::getRowByDateAndProvince($rowProvince[$i]["id"],$date);                 
        }
        $this->render('miennam',array("rows"=>$rows,"day"=>$day,"rowProvince"=>$rowProvince));

    } 

    public function actionSaveGiaiTamMiennam(){
        $user = Yii::app()->user->name;
        $giai_tam       = isset($_POST["giai_tam"])     ?rtrim($_POST["giai_tam"],";")      :"";
        $province_id    = isset($_POST["province_id"])  ?rtrim($_POST["province_id"],";")   :"";
        $ngay_quay      = isset($_POST["ngay_quay"])    ?$_POST["ngay_quay"]                :"";

        $arr_tam = explode(";",$giai_tam);
        $arr_prov = explode(";",$province_id);
        for($i=0;$i<count($arr_prov);$i++){
            if(isset($arr_tam[$i])){

                $row = AdminKqMiennam::getRowByDateAndProvince($arr_prov[$i],$ngay_quay);
                if(!$row){                   
                    $last_id = AdminKqMiennam::insertGiaiTam($arr_prov[$i],$arr_tam[$i],$ngay_quay,$user);
                    //echo 'bbb';die;
                }else{
                    //echo 'aaaa'; die;
                    $result = AdminKqMiennam::updateGiaiTam($row["id"],$arr_tam[$i],$user);
                    $last_id = $row["id"];
                }
                $row_update = AdminKqMiennam::getRowById($last_id);
                /*$this->setCacheMienNam($row_update);*/
                /*$boso1 = substr($arr_tam[$i],strlen($arr_tam[$i])-2,2);
                if($boso1 !=0 && $boso1 !=""){            

                $last_boso_id = AdminKqMiennam::insertThongke($last_id,$boso1,$ngay_quay,"G8",$user);

                } */
            }

        } 

        if($last_id !=0){
            echo 1;
        }else{
            echo 0;
        }
    }

    public function actionSaveGiaiBayMiennam(){
        $user = Yii::app()->user->name;
        $giai_bay       = isset($_POST["giai_bay"])     ?rtrim($_POST["giai_bay"],";")      :"";
        $province_id    = isset($_POST["province_id"])  ?rtrim($_POST["province_id"],";")   :"";
        $ngay_quay      = isset($_POST["ngay_quay"])    ?$_POST["ngay_quay"]                :"";

        $arr_bay = explode(";",$giai_bay);
        $arr_prov = explode(";",$province_id);
        for($i=0;$i<count($arr_prov);$i++){
            if(isset($arr_bay[$i])){

                $row = AdminKqMiennam::getRowByDateAndProvince($arr_prov[$i],$ngay_quay);
                if(!$row){                 
                    $last_id = AdminKqMiennam::insertGiaiBay($arr_prov[$i],$arr_bay[$i],$ngay_quay,$user);                  
                }else{

                    $result = AdminKqMiennam::updateGiaiBay($row["id"],$arr_bay[$i],$user);
                    //echo $result.',';
                    $last_id = $row["id"];
                }
                $row_update = AdminKqMiennam::getRowById($last_id);
                /*$this->setCacheMienNam($row_update);*/
                //echo $last_id;die;
                /*$boso1 = substr($arr_bay[$i],strlen($arr_bay[$i])-2,2);
                if($boso1 !=0 && $boso1 !=""){            

                $last_boso_id = AdminKqMiennam::insertThongke($last_id,$boso1,$ngay_quay,"G7",$user);

                }  */
            }

        } 
        //die;
        if($last_id !=0){
            echo 1;
        }else{
            echo 0;
        }
    }

    public function actionSaveGiaiSauMiennam(){
        $last_id = 0;
        //echo '11111';die;
        $user = Yii::app()->user->name;
        $giai_sau_1     = isset($_POST["giai_sau_1"])   ?rtrim($_POST["giai_sau_1"],";")    :"";
        $giai_sau_2     = isset($_POST["giai_sau_2"])   ?rtrim($_POST["giai_sau_2"],";")    :"";
        $giai_sau_3     = isset($_POST["giai_sau_3"])   ?rtrim($_POST["giai_sau_3"],";")    :"";
        $province_id    = isset($_POST["province_id"])  ?$_POST["province_id"]              :"";
        $ngay_quay      = isset($_POST["ngay_quay"])    ?$_POST["ngay_quay"]                :"";

        $arr_sau_1  = explode(";",$giai_sau_1);
        $arr_sau_2  = explode(";",$giai_sau_2);
        $arr_sau_3  = explode(";",$giai_sau_3);
        $arr_prov   = explode(";",$province_id);
        //var_dump($arr_prov);die;
        for($i=0;$i<count($arr_prov);$i++){
            if(isset($arr_sau_1[$i]) || isset($arr_sau_2[$i]) || isset($arr_sau_3[$i])){
                $row = AdminKqMiennam::getRowByDateAndProvince($arr_prov[$i],$ngay_quay);
                if(!$row){ 
                    //echo 'aaa';die;                
                    $last_id = AdminKqMiennam::insertGiaiSau($arr_prov[$i],$arr_sau_1[$i],$arr_sau_2[$i],$arr_sau_3[$i],$ngay_quay,$user);                  
                }else{
                    //echo 'bbbb';die;
                    $result = AdminKqMiennam::updateGiaiSau($row["id"],$arr_sau_1[$i],$arr_sau_2[$i],$arr_sau_3[$i],$user);

                    $last_id = $row["id"];
                }
                $row_update = AdminKqMiennam::getRowById($last_id);
                /*$this->setCacheMienNam($row_update);*/
                //echo $last_id;die;
                /*$boso1 = isset($arr_sau_1[$i]) && $arr_sau_1[$i] !="" ? substr($arr_sau_1[$i],strlen($arr_sau_1[$i])-2,2):"";
                $boso2 = isset($arr_sau_2[$i]) && $arr_sau_2[$i] !="" ? substr($arr_sau_2[$i],strlen($arr_sau_2[$i])-2,2):"";
                $boso3 = isset($arr_sau_3[$i]) && $arr_sau_3[$i] !="" ? substr($arr_sau_3[$i],strlen($arr_sau_3[$i])-2,2):"";
                //echo $boso2;die;
                if($boso1 !=0 && $boso1 !=""){            

                $last_boso_id = AdminKqMiennam::insertThongke($last_id,$boso1,$ngay_quay,"G61",$user);

                }
                if($boso2 !=0 && $boso2 !=""){            

                $last_boso_id = AdminKqMiennam::insertThongke($last_id,$boso2,$ngay_quay,"G62",$user);

                }
                if($boso3 !=0 && $boso3 !=""){            

                $last_boso_id = AdminKqMiennam::insertThongke($last_id,$boso3,$ngay_quay,"G63",$user);

                } */
            }

        } 
        //die;
        if($last_id !=0){
            echo 1;
        }else{
            echo 0;
        }
    }

    public function actionSaveGiaiNamMiennam(){
        //echo '11111';die;
        $user = Yii::app()->user->name;
        $giai_nam       = isset($_POST["giai_nam"])     ?rtrim($_POST["giai_nam"],";")      :"";
        $province_id    = isset($_POST["province_id"])  ?rtrim($_POST["province_id"],";")   :"";
        $ngay_quay      = isset($_POST["ngay_quay"])    ?$_POST["ngay_quay"]                :"";

        $arr_nam = explode(";",$giai_nam);
        $arr_prov = explode(";",$province_id);
        for($i=0;$i<count($arr_prov);$i++){
            if(isset($arr_nam[$i])){

                $row = AdminKqMiennam::getRowByDateAndProvince($arr_prov[$i],$ngay_quay);
                if(!$row){                 
                    $last_id = AdminKqMiennam::insertGiaiNam($arr_prov[$i],$arr_nam[$i],$ngay_quay,$user);                  
                }else{

                    $result = AdminKqMiennam::updateGiaiNam($row["id"],$arr_nam[$i],$user);
                    //echo $result.',';
                    $last_id = $row["id"];
                }
                $row_update = AdminKqMiennam::getRowById($last_id);
                /*$this->setCacheMienNam($row_update);*/
                //echo $last_id;die;
                /*$boso1 = substr($arr_nam[$i],strlen($arr_nam[$i])-2,2);
                if($boso1 !=0 && $boso1 !=""){            

                $last_boso_id = AdminKqMiennam::insertThongke($last_id,$boso1,$ngay_quay,"G5",$user);

                } */
            }

        } 
        //die;
        if($last_id !=0){
            echo 1;
        }else{
            echo 0;
        }


    }

    public function actionSaveGiaiTuMiennam(){

        $last_id = 0;
        //echo '11111';die;
        $user = Yii::app()->user->name;
        $giai_tu_1      = isset($_POST["giai_tu_1"])     ?rtrim($_POST["giai_tu_1"],";")    :"";
        $giai_tu_2      = isset($_POST["giai_tu_2"])     ?rtrim($_POST["giai_tu_2"],";")    :"";
        $giai_tu_3      = isset($_POST["giai_tu_3"])     ?rtrim($_POST["giai_tu_3"],";")    :"";
        $giai_tu_4      = isset($_POST["giai_tu_4"])     ?rtrim($_POST["giai_tu_4"],";")    :"";
        $giai_tu_5      = isset($_POST["giai_tu_5"])     ?rtrim($_POST["giai_tu_5"],";")    :"";
        $giai_tu_6      = isset($_POST["giai_tu_6"])     ?rtrim($_POST["giai_tu_6"],";")    :"";
        $giai_tu_7      = isset($_POST["giai_tu_7"])     ?rtrim($_POST["giai_tu_7"],";")    :"";
        $province_id    = isset($_POST["province_id"])   ?rtrim($_POST["province_id"],";")  :"";
        $ngay_quay      = isset($_POST["ngay_quay"])     ?$_POST["ngay_quay"]               :"";

        $arr_tu_1 = explode(";",$giai_tu_1);
        $arr_tu_2 = explode(";",$giai_tu_2);
        $arr_tu_3 = explode(";",$giai_tu_3);
        $arr_tu_4 = explode(";",$giai_tu_4);
        $arr_tu_5 = explode(";",$giai_tu_5);
        $arr_tu_6 = explode(";",$giai_tu_6);
        $arr_tu_7 = explode(";",$giai_tu_7);
        $arr_prov = explode(";",$province_id);
        //var_dump($arr_prov);die;
        for($i=0;$i<count($arr_prov);$i++){
            if(isset($arr_tu_1[$i])|| isset($arr_tu_2[$i]) || isset($arr_tu_3[$i]) || isset($arr_tu_4[$i]) || isset($arr_tu_5[$i]) || isset($arr_tu_6[$i]) || isset($arr_tu_7[$i])){
                $row = AdminKqMiennam::getRowByDateAndProvince($arr_prov[$i],$ngay_quay);
                if(!$row){               
                    $last_id = AdminKqMiennam::insertGiaiTu($arr_prov[$i],$arr_tu_1[$i],$arr_tu_2[$i],$arr_tu_3[$i],$arr_tu_4[$i],$arr_tu_5[$i],$arr_tu_6[$i],$arr_tu_7[$i],$ngay_quay,$user);                  
                }else{
                    $result = AdminKqMiennam::updateGiaiTu($row["id"],$arr_tu_1[$i],$arr_tu_2[$i],$arr_tu_3[$i],$arr_tu_4[$i],$arr_tu_5[$i],$arr_tu_6[$i],$arr_tu_7[$i],$user);
                    //echo $result;die;
                    $last_id = $row["id"];
                }
                $row_update = AdminKqMiennam::getRowById($last_id);
                /*$this->setCacheMienNam($row_update);*/
                /*$boso1 = isset($arr_tu_1[$i]) && $arr_tu_1[$i] !="" ? substr($arr_tu_1[$i],strlen($arr_tu_1[$i])-2,2):"";               
                $boso2 = isset($arr_tu_2[$i]) && $arr_tu_2[$i] !="" ? substr($arr_tu_2[$i],strlen($arr_tu_2[$i])-2,2):""; 
                $boso3 = isset($arr_tu_3[$i]) && $arr_tu_3[$i] !="" ? substr($arr_tu_3[$i],strlen($arr_tu_3[$i])-2,2):"";               
                $boso4 = isset($arr_tu_4[$i]) && $arr_tu_4[$i] !="" ? substr($arr_tu_4[$i],strlen($arr_tu_4[$i])-2,2):"";                
                $boso5 = isset($arr_tu_5[$i]) && $arr_tu_5[$i] !="" ? substr($arr_tu_5[$i],strlen($arr_tu_5[$i])-2,2):"";
                $boso6 = isset($arr_tu_6[$i]) && $arr_tu_6[$i] !="" ? substr($arr_tu_6[$i],strlen($arr_tu_6[$i])-2,2):"";
                $boso7 = isset($arr_tu_7[$i]) && $arr_tu_7[$i] !="" ? substr($arr_tu_7[$i],strlen($arr_tu_7[$i])-2,2):"";

                if($boso1 !=0 && $boso1 !=""){            

                $last_boso_id = AdminKqMiennam::insertThongke($last_id,$boso1,$ngay_quay,"G41",$user);

                }
                if($boso2 !=0 && $boso2 !=""){            

                $last_boso_id = AdminKqMiennam::insertThongke($last_id,$boso2,$ngay_quay,"G42",$user);

                }
                if($boso3 !=0 && $boso3 !=""){            

                $last_boso_id = AdminKqMiennam::insertThongke($last_id,$boso3,$ngay_quay,"G43",$user);

                }
                if($boso4 !=0 && $boso4 !=""){            

                $last_boso_id = AdminKqMiennam::insertThongke($last_id,$boso4,$ngay_quay,"G44",$user);

                }

                if($boso5 !=0 && $boso5 !=""){            

                $last_boso_id = AdminKqMiennam::insertThongke($last_id,$boso5,$ngay_quay,"G45",$user);

                }
                if($boso6 !=0 && $boso6 !=""){            

                $last_boso_id = AdminKqMiennam::insertThongke($last_id,$boso6,$ngay_quay,"G46",$user);

                }

                if($boso7 !=0 && $boso7 !=""){            

                $last_boso_id = AdminKqMiennam::insertThongke($last_id,$boso7,$ngay_quay,"G47",$user);

                }*/            
            }

        } 
        if($last_id !=0){
            echo 1;
        }else{
            echo 0;
        }
    }

    public function actionSaveGiaiBaMiennam(){

        $last_id = 0;
        //echo '11111';die;
        $user = Yii::app()->user->name;
        $giai_ba_1      = isset($_POST["giai_ba_1"])        ?rtrim($_POST["giai_ba_1"],";")     :"";
        $giai_ba_2      = isset($_POST["giai_ba_2"])        ?rtrim($_POST["giai_ba_2"],";")     :"";
        $province_id    = isset($_POST["province_id"])      ?rtrim($_POST["province_id"],";")   :"";
        $ngay_quay      = isset($_POST["ngay_quay"])        ?$_POST["ngay_quay"]                :"";

        $arr_ba_1 = explode(";",$giai_ba_1);       
        $arr_ba_2 = explode(";",$giai_ba_2);
        $arr_prov = explode(";",$province_id);
        //var_dump($arr_prov);die;
        for($i=0;$i<count($arr_prov);$i++){
            if(isset($arr_ba_1[$i]) || isset($arr_ba_2[$i])){
                $row = AdminKqMiennam::getRowByDateAndProvince($arr_prov[$i],$ngay_quay);
                if(!$row){               
                    $last_id = AdminKqMiennam::insertGiaiBa($arr_prov[$i],$arr_ba_1[$i],$arr_ba_2[$i],$ngay_quay,$user);                  
                }else{
                    $result = AdminKqMiennam::updateGiaiBa($row["id"],$arr_ba_1[$i],$arr_ba_2[$i],$user);
                    //echo $result;die;
                    $last_id = $row["id"];
                }
                $row_update = AdminKqMiennam::getRowById($last_id);
                /*$this->setCacheMienNam($row_update);*/
                /*$boso1 = isset($arr_ba_1[$i]) && $arr_ba_1[$i] !="" ? substr($arr_ba_1[$i],strlen($arr_ba_1[$i])-2,2):"";               
                $boso2 = isset($arr_ba_2[$i]) && $arr_ba_2[$i] !="" ? substr($arr_ba_2[$i],strlen($arr_ba_2[$i])-2,2):""; 

                if($boso1 !=0 && $boso1 !=""){            

                $last_boso_id = AdminKqMiennam::insertThongke($last_id,$boso1,$ngay_quay,"G31",$user);

                }
                if($boso2 !=0 && $boso2 !=""){            

                $last_boso_id = AdminKqMiennam::insertThongke($last_id,$boso2,$ngay_quay,"G32",$user);

                }*/     
            }

        } 
        if($last_id !=0){
            echo 1;
        }else{
            echo 0;
        }
    }

    public function actionSaveGiaiNhiMiennam(){

        $last_id = 0;
        //echo '11111';die;
        $user = Yii::app()->user->name;
        $giai_nhi       = isset($_POST["giai_nhi"])     ?rtrim($_POST["giai_nhi"],";")      :"";
        $province_id    = isset($_POST["province_id"])  ?rtrim($_POST["province_id"],";")   :"";
        $ngay_quay      = isset($_POST["ngay_quay"])    ?$_POST["ngay_quay"]                :"";

        $arr_nhi = explode(";",$giai_nhi);       
        $arr_prov = explode(";",$province_id);
        //var_dump($arr_prov);die;
        for($i=0;$i<count($arr_prov);$i++){
            if(isset($arr_nhi[$i])){
                $row = AdminKqMiennam::getRowByDateAndProvince($arr_prov[$i],$ngay_quay);
                if(!$row){               
                    $last_id = AdminKqMiennam::insertGiaiNhi($arr_prov[$i],$arr_nhi[$i],$ngay_quay,$user);                  
                }else{
                    $result = AdminKqMiennam::updateGiaiNhi($row["id"],$arr_nhi[$i],$user);
                    //echo $result;die;
                    $last_id = $row["id"];
                }
                $row_update = AdminKqMiennam::getRowById($last_id);
                /*$this->setCacheMienNam($row_update);*/
                /*$boso1 = isset($arr_nhi[$i]) && $arr_nhi[$i] !="" ? substr($arr_nhi[$i],strlen($arr_nhi[$i])-2,2):"";               

                if($boso1 !=0 && $boso1 !=""){            

                $last_boso_id = AdminKqMiennam::insertThongke($last_id,$boso1,$ngay_quay,"G2",$user);

                } */
            }

        } 
        if($last_id !=0){
            echo 1;
        }else{
            echo 0;
        }
    }

    public function actionSaveGiaiNhatMiennam(){

        $last_id = 0;
        //echo '11111';die;
        $user = Yii::app()->user->name;
        $giai_nhat      = isset($_POST["giai_nhat"])        ?rtrim($_POST["giai_nhat"],";")     :"";
        $province_id    = isset($_POST["province_id"])      ?rtrim($_POST["province_id"],";")   :"";
        $ngay_quay      = isset($_POST["ngay_quay"])        ?$_POST["ngay_quay"]                :"";

        $arr_nhat = explode(";",$giai_nhat);       
        $arr_prov = explode(";",$province_id);
        //var_dump($arr_prov);die;
        for($i=0;$i<count($arr_prov);$i++){
            if( isset($arr_nhat[$i])){
                $row = AdminKqMiennam::getRowByDateAndProvince($arr_prov[$i],$ngay_quay);
                if(!$row){               
                    $last_id = AdminKqMiennam::insertGiaiNhat($arr_prov[$i],$arr_nhat[$i],$ngay_quay,$user);                  
                }else{
                    $result = AdminKqMiennam::updateGiaiNhat($row["id"],$arr_nhat[$i],$user);
                    //echo $result;die;
                    $last_id = $row["id"];
                }
                $row_update = AdminKqMiennam::getRowById($last_id);
                /*$this->setCacheMienNam($row_update);*/
                /*$boso1 = isset($arr_nhat[$i]) && $arr_nhat[$i] !="" ? substr($arr_nhat[$i],strlen($arr_nhat[$i])-2,2):"";               

                if($boso1 !=0 && $boso1 !=""){            

                $last_boso_id = AdminKqMiennam::insertThongke($last_id,$boso1,$ngay_quay,"G1",$user);

                }   */
            }

        } 
        if($last_id !=0){
            echo 1;
        }else{
            echo 0;
        }
    }

    public function actionSaveGiaiDacbietMiennam(){
        
        $last_id = 0;
        //echo '11111';die;
        $user = Yii::app()->user->name;
        $giai_dacbiet   = isset($_POST["giai_dacbiet"])     ?rtrim($_POST["giai_dacbiet"],";")      :"";
        $province_id    = isset($_POST["province_id"])      ?rtrim($_POST["province_id"],";")       :"";
        $ngay_quay      = isset($_POST["ngay_quay"])        ?$_POST["ngay_quay"]                    :"";

        $arr_dacbiet    = explode(";",$giai_dacbiet);       
        $arr_prov       = explode(";",$province_id);
        
        //echo count($arr_prov);die;
        for($i=0;$i<count($arr_prov);$i++){
            if(isset($arr_dacbiet[$i])){
                 
                $row = AdminKqMiennam::getRowByDateAndProvince($arr_prov[$i],$ngay_quay);
                 
                if(!$row){               
                    $last_id = AdminKqMiennam::insertGiaiDacbiet($arr_prov[$i],$arr_dacbiet[$i],$ngay_quay,$user);                  
                }else{
                    
                    $result = AdminKqMiennam::updateGiaiDacbiet($row["id"],$arr_dacbiet[$i],$user);
                    
                    $last_id = $row["id"];
                }
                $row_update = AdminKqMiennam::getRowById($last_id);
                
                /*$this->setCacheMienNam($row_update);*/
                /*$boso1 = isset($arr_dacbiet[$i]) && $arr_dacbiet[$i] !="" ? substr($arr_dacbiet[$i],strlen($arr_dacbiet[$i])-2,2):"";               

                if($boso1 !=0 && $boso1 !=""){            

                $last_boso_id = AdminKqMiennam::insertThongke($last_id,$boso1,$ngay_quay,"GDB",$user);

                }   */
            }

        }
        
        if($last_id !=0){
            echo 1;
        }else{
            echo 0;
        }
    }

    public function actionMientrung(){
        $row = array();
        $date = date("Y-m-d",time()); 
        $day = getdate(time());
        $wday = $day["wday"]; 
        $day_of_week = StringUtils::getDayVi($wday);  
        $mien_trung = ConstantsUtil::MIEN_TRUNG; 
        $rowProvince = AdminProvince::model()->getRowsByDateAndRegion($mien_trung,$day_of_week);
        for($i=0;$i<count($rowProvince);$i++){
            $rows[$i] = AdminKqMientrung::getRowByDateAndProvince($rowProvince[$i]["id"],$date);                 
        }
        $this->render('mientrung',array("rows"=>$rows,"day"=>$day,"rowProvince"=>$rowProvince));

    }

    public function actionSaveGiaiTamMientrung(){
        $user = Yii::app()->user->name;
        $giai_tam       = isset($_POST["giai_tam"])     ?rtrim($_POST["giai_tam"],";")      :"";
        $province_id    = isset($_POST["province_id"])  ?rtrim($_POST["province_id"],";")   :"";
        $ngay_quay      = isset($_POST["ngay_quay"])    ?$_POST["ngay_quay"]                :"";

        $arr_tam    = explode(";",$giai_tam);
        $arr_prov   = explode(";",$province_id);
        for($i=0;$i<count($arr_prov);$i++){
            if( isset($arr_tam[$i])){

                $row = AdminKqMientrung::getRowByDateAndProvince($arr_prov[$i],$ngay_quay);
                if(!$row){                   
                    $last_id = AdminKqMientrung::insertGiaiTam($arr_prov[$i],$arr_tam[$i],$ngay_quay,$user);
                    //echo 'bbb';die;
                }else{
                    //echo 'aaaa'; die;
                    $result = AdminKqMientrung::updateGiaiTam($row["id"],$arr_tam[$i],$user);
                    $last_id = $row["id"];
                }
                $row_update = AdminKqMientrung::getRowById($last_id);
                /*$this->setCacheMienTrung($row_update);*/
                //echo $last_id;die;
                /*$boso1 = substr($arr_tam[$i],strlen($arr_tam[$i])-2,2);
                if($boso1 !=0 && $boso1 !=""){            

                $last_boso_id = AdminKqMientrung::insertThongke($last_id,$boso1,$ngay_quay,"G8",$user);

                }   */
            }

        } 

        if($last_id !=0){
            echo 1;
        }else{
            echo 0;
        }
    }

    public function actionSaveGiaiBayMientrung(){
        //echo '11111';die;
        $user = Yii::app()->user->name;
        $giai_bay       = isset($_POST["giai_bay"])     ?rtrim($_POST["giai_bay"],";")      :"";
        $province_id    = isset($_POST["province_id"])  ?rtrim($_POST["province_id"],";")   :"";
        $ngay_quay      = isset($_POST["ngay_quay"])    ?$_POST["ngay_quay"]                :"";

        $arr_bay    = explode(";",$giai_bay);
        $arr_prov   = explode(";",$province_id);
        for($i=0;$i<count($arr_prov);$i++){
            if( isset($arr_bay[$i])){

                $row = AdminKqMientrung::getRowByDateAndProvince($arr_prov[$i],$ngay_quay);
                if(!$row){                 
                    $last_id = AdminKqMientrung::insertGiaiBay($arr_prov[$i],$arr_bay[$i],$ngay_quay,$user);                  
                }else{

                    $result = AdminKqMientrung::updateGiaiBay($row["id"],$arr_bay[$i],$user);
                    //echo $result.',';
                    $last_id = $row["id"];
                }
                $row_update = AdminKqMientrung::getRowById($last_id);
                /*$this->setCacheMienTrung($row_update);*/
                //echo $last_id;die;
                /*$boso1 = substr($arr_bay[$i],strlen($arr_bay[$i])-2,2);
                if($boso1 !=0 && $boso1 !=""){            

                $last_boso_id = AdminKqMientrung::insertThongke($last_id,$boso1,$ngay_quay,"G7",$user);

                }  */
            }

        } 
        //die;
        if($last_id !=0){
            echo 1;
        }else{
            echo 0;
        }
    }

    public function actionSaveGiaiSauMientrung(){
        $last_id = 0;
        //echo '11111';die;
        $user = Yii::app()->user->name;
        $giai_sau_1     = isset($_POST["giai_sau_1"])   ?rtrim($_POST["giai_sau_1"],";")    :"";
        $giai_sau_2     = isset($_POST["giai_sau_2"])   ?rtrim($_POST["giai_sau_2"],";")    :"";
        $giai_sau_3     = isset($_POST["giai_sau_3"])   ?rtrim($_POST["giai_sau_3"],";")    :"";
        $province_id    = isset($_POST["province_id"])  ?$_POST["province_id"]              :"";
        $ngay_quay      = isset($_POST["ngay_quay"])    ?$_POST["ngay_quay"]                :"";

        $arr_sau_1  = explode(";",$giai_sau_1);
        $arr_sau_2  = explode(";",$giai_sau_2);
        $arr_sau_3  = explode(";",$giai_sau_3);
        $arr_prov   = explode(";",$province_id);
        //var_dump($arr_prov);die;
        for($i=0;$i<count($arr_prov);$i++){
            if(isset($arr_sau_1[$i]) || isset($arr_sau_2[$i]) || isset($arr_sau_3[$i])){
                $row = AdminKqMientrung::getRowByDateAndProvince($arr_prov[$i],$ngay_quay);
                if(!$row){ 
                    //echo 'aaa';die;                
                    $last_id = AdminKqMientrung::insertGiaiSau($arr_prov[$i],$arr_sau_1[$i],$arr_sau_2[$i],$arr_sau_3[$i],$ngay_quay,$user);                  
                }else{
                    //echo 'bbbb';die;
                    $result = AdminKqMientrung::updateGiaiSau($row["id"],$arr_sau_1[$i],$arr_sau_2[$i],$arr_sau_3[$i],$user);

                    $last_id = $row["id"];
                }
                $row_update = AdminKqMientrung::getRowById($last_id);
                /*$this->setCacheMienTrung($row_update);*/
                //echo $last_id;die;
                /*$boso1 = isset($arr_sau_1[$i]) && $arr_sau_1[$i] !="" ? substr($arr_sau_1[$i],strlen($arr_sau_1[$i])-2,2):"";
                $boso2 = isset($arr_sau_2[$i]) && $arr_sau_2[$i] !="" ? substr($arr_sau_2[$i],strlen($arr_sau_2[$i])-2,2):"";
                $boso3 = isset($arr_sau_3[$i]) && $arr_sau_3[$i] !="" ? substr($arr_sau_3[$i],strlen($arr_sau_3[$i])-2,2):"";
                //echo $boso2;die;
                if($boso1 !=0 && $boso1 !=""){            

                $last_boso_id = AdminKqMientrung::insertThongke($last_id,$boso1,$ngay_quay,"G61",$user);

                }
                if($boso2 !=0 && $boso2 !=""){            

                $last_boso_id = AdminKqMientrung::insertThongke($last_id,$boso2,$ngay_quay,"G62",$user);

                }
                if($boso3 !=0 && $boso3 !=""){            

                $last_boso_id = AdminKqMientrung::insertThongke($last_id,$boso3,$ngay_quay,"G63",$user);

                }  */
            }

        } 
        //die;
        if($last_id !=0){
            echo 1;
        }else{
            echo 0;
        }
    }

    public function actionSaveGiaiNamMientrung(){
        //echo '11111';die;
        $user = Yii::app()->user->name;
        $giai_nam       = isset($_POST["giai_nam"])     ?rtrim($_POST["giai_nam"],";")      :"";
        $province_id    = isset($_POST["province_id"])  ?rtrim($_POST["province_id"],";")   :"";
        $ngay_quay      = isset($_POST["ngay_quay"])    ?$_POST["ngay_quay"]                :""; 

        $arr_nam    = explode(";",$giai_nam);
        $arr_prov   = explode(";",$province_id);
        for($i=0;$i<count($arr_prov);$i++){
            if( isset($arr_nam[$i])){

                $row = AdminKqMientrung::getRowByDateAndProvince($arr_prov[$i],$ngay_quay);
                if(!$row){                 
                    $last_id = AdminKqMientrung::insertGiaiNam($arr_prov[$i],$arr_nam[$i],$ngay_quay,$user);                  
                }else{

                    $result = AdminKqMientrung::updateGiaiNam($row["id"],$arr_nam[$i],$user);
                    //echo $result.',';
                    $last_id = $row["id"];
                }
                $row_update = AdminKqMientrung::getRowById($last_id);
                /*$this->setCacheMienTrung($row_update);*/
                //echo $last_id;die;
                /*$boso1 = substr($arr_nam[$i],strlen($arr_nam[$i])-2,2);
                if($boso1 !=0 && $boso1 !=""){            

                $last_boso_id = AdminKqMientrung::insertThongke($last_id,$boso1,$ngay_quay,"G5",$user);

                } */
            }

        } 
        //die;
        if($last_id !=0){
            echo 1;
        }else{
            echo 0;
        }


    }

    public function actionSaveGiaiTuMientrung(){

        $last_id = 0;
        //echo '11111';die;
        $user = Yii::app()->user->name;
        $giai_tu_1      = isset($_POST["giai_tu_1"])     ?rtrim($_POST["giai_tu_1"],";")    :"";
        $giai_tu_2      = isset($_POST["giai_tu_2"])     ?rtrim($_POST["giai_tu_2"],";")    :"";
        $giai_tu_3      = isset($_POST["giai_tu_3"])     ?rtrim($_POST["giai_tu_3"],";")    :"";
        $giai_tu_4      = isset($_POST["giai_tu_4"])     ?rtrim($_POST["giai_tu_4"],";")    :"";
        $giai_tu_5      = isset($_POST["giai_tu_5"])     ?rtrim($_POST["giai_tu_5"],";")    :"";
        $giai_tu_6      = isset($_POST["giai_tu_6"])     ?rtrim($_POST["giai_tu_6"],";")    :"";
        $giai_tu_7      = isset($_POST["giai_tu_7"])     ?rtrim($_POST["giai_tu_7"],";")    :"";
        $province_id    = isset($_POST["province_id"])   ?rtrim($_POST["province_id"],";")  :"";
        $ngay_quay      = isset($_POST["ngay_quay"])     ?$_POST["ngay_quay"]               :"";
        
        $arr_tu_1 = explode(";",$giai_tu_1);
        $arr_tu_2 = explode(";",$giai_tu_2);
        $arr_tu_3 = explode(";",$giai_tu_3);
        $arr_tu_4 = explode(";",$giai_tu_4);
        $arr_tu_5 = explode(";",$giai_tu_5);
        $arr_tu_6 = explode(";",$giai_tu_6);
        $arr_tu_7 = explode(";",$giai_tu_7);
        $arr_prov = explode(";",$province_id);
        //var_dump($arr_prov);die;
        for($i=0;$i<count($arr_prov);$i++){
            if(isset($arr_tu_1[$i]) || isset($arr_tu_2[$i]) || isset($arr_tu_3[$i]) || isset($arr_tu_4[$i]) || isset($arr_tu_5[$i]) || isset($arr_tu_6[$i])|| isset($arr_tu_7[$i])){
                $row = AdminKqMientrung::getRowByDateAndProvince($arr_prov[$i],$ngay_quay);
                if(!$row){               
                    $last_id = AdminKqMientrung::insertGiaiTu($arr_prov[$i],$arr_tu_1[$i],$arr_tu_2[$i],$arr_tu_3[$i],$arr_tu_4[$i],$arr_tu_5[$i],$arr_tu_6[$i],$arr_tu_7[$i],$ngay_quay,$user);                  
                }else{
                    $result = AdminKqMientrung::updateGiaiTu($row["id"],$arr_tu_1[$i],$arr_tu_2[$i],$arr_tu_3[$i],$arr_tu_4[$i],$arr_tu_5[$i],$arr_tu_6[$i],$arr_tu_7[$i],$user);
                    //echo $result;die;
                    $last_id = $row["id"];
                }
                $row_update = AdminKqMientrung::getRowById($last_id);
                /*$this->setCacheMienTrung($row_update);*/
                /*$boso1 = isset($arr_tu_1[$i]) && $arr_tu_1[$i] !="" ? substr($arr_tu_1[$i],strlen($arr_tu_1[$i])-2,2):"";               
                $boso2 = isset($arr_tu_2[$i]) && $arr_tu_2[$i] !="" ? substr($arr_tu_2[$i],strlen($arr_tu_2[$i])-2,2):""; 
                $boso3 = isset($arr_tu_3[$i]) && $arr_tu_3[$i] !="" ? substr($arr_tu_3[$i],strlen($arr_tu_3[$i])-2,2):"";               
                $boso4 = isset($arr_tu_4[$i]) && $arr_tu_4[$i] !="" ? substr($arr_tu_4[$i],strlen($arr_tu_4[$i])-2,2):"";                
                $boso5 = isset($arr_tu_5[$i]) && $arr_tu_5[$i] !="" ? substr($arr_tu_5[$i],strlen($arr_tu_5[$i])-2,2):"";
                $boso6 = isset($arr_tu_6[$i]) && $arr_tu_6[$i] !="" ? substr($arr_tu_6[$i],strlen($arr_tu_6[$i])-2,2):"";
                $boso7 = isset($arr_tu_7[$i]) && $arr_tu_7[$i] !="" ? substr($arr_tu_7[$i],strlen($arr_tu_7[$i])-2,2):"";

                if($boso1 !=0 && $boso1 !=""){            

                $last_boso_id = AdminKqMientrung::insertThongke($last_id,$boso1,$ngay_quay,"G41",$user);

                }
                if($boso2 !=0 && $boso2 !=""){            

                $last_boso_id = AdminKqMientrung::insertThongke($last_id,$boso2,$ngay_quay,"G42",$user);

                }
                if($boso3 !=0 && $boso3 !=""){            

                $last_boso_id = AdminKqMientrung::insertThongke($last_id,$boso3,$ngay_quay,"G43",$user);

                }
                if($boso4 !=0 && $boso4 !=""){            

                $last_boso_id = AdminKqMientrung::insertThongke($last_id,$boso4,$ngay_quay,"G44",$user);

                }

                if($boso5 !=0 && $boso5 !=""){            

                $last_boso_id = AdminKqMientrung::insertThongke($last_id,$boso5,$ngay_quay,"G45",$user);

                }
                if($boso6 !=0 && $boso6 !=""){            

                $last_boso_id = AdminKqMientrung::insertThongke($last_id,$boso6,$ngay_quay,"G46",$user);

                }

                if($boso7 !=0 && $boso7 !=""){            

                $last_boso_id = AdminKqMientrung::insertThongke($last_id,$boso7,$ngay_quay,"G47",$user);

                }        */    
            }

        } 
        if($last_id !=0){
            echo 1;
        }else{
            echo 0;
        }
    }

    public function actionSaveGiaiBaMientrung(){

        $last_id = 0;
        //echo '11111';die;
        $user = Yii::app()->user->name;
        $giai_ba_1      = isset($_POST["giai_ba_1"])        ?rtrim($_POST["giai_ba_1"],";")     :"";
        $giai_ba_2      = isset($_POST["giai_ba_2"])        ?rtrim($_POST["giai_ba_2"],";")     :"";
        $province_id    = isset($_POST["province_id"])      ?rtrim($_POST["province_id"],";")   :"";
        $ngay_quay      = isset($_POST["ngay_quay"])        ?$_POST["ngay_quay"]                :"";

        $arr_ba_1 = explode(";",$giai_ba_1);       
        $arr_ba_2 = explode(";",$giai_ba_2);
        $arr_prov = explode(";",$province_id);
        //var_dump($arr_prov);die;
        for($i=0;$i<count($arr_prov);$i++){
            if( isset($arr_ba_1[$i]) || isset($arr_ba_2[$i])){
                $row = AdminKqMientrung::getRowByDateAndProvince($arr_prov[$i],$ngay_quay);
                if(!$row){               
                    $last_id = AdminKqMientrung::insertGiaiBa($arr_prov[$i],$arr_ba_1[$i],$arr_ba_2[$i],$ngay_quay,$user);                  
                }else{
                    $result = AdminKqMientrung::updateGiaiBa($row["id"],$arr_ba_1[$i],$arr_ba_2[$i],$user);
                    //echo $result;die;
                    $last_id = $row["id"];
                }
                $row_update = AdminKqMientrung::getRowById($last_id);
                /*$this->setCacheMienTrung($row_update);*/
                /*$boso1 = isset($arr_ba_1[$i]) && $arr_ba_1[$i] !="" ? substr($arr_ba_1[$i],strlen($arr_ba_1[$i])-2,2):"";               
                $boso2 = isset($arr_ba_2[$i]) && $arr_ba_2[$i] !="" ? substr($arr_ba_2[$i],strlen($arr_ba_2[$i])-2,2):""; 

                if($boso1 !=0 && $boso1 !=""){            

                $last_boso_id = AdminKqMientrung::insertThongke($last_id,$boso1,$ngay_quay,"G31",$user);

                }
                if($boso2 !=0 && $boso2 !=""){            

                $last_boso_id = AdminKqMientrung::insertThongke($last_id,$boso2,$ngay_quay,"G32",$user);

                }*/     
            }

        } 
        if($last_id !=0){
            echo 1;
        }else{
            echo 0;
        }
    }

    public function actionSaveGiaiNhiMientrung(){

        $last_id = 0;
        //echo '11111';die;
        $user = Yii::app()->user->name;
        $giai_nhi       = isset($_POST["giai_nhi"])     ?rtrim($_POST["giai_nhi"],";")      :"";
        $province_id    = isset($_POST["province_id"])  ?rtrim($_POST["province_id"],";")   :"";
        $ngay_quay      = isset($_POST["ngay_quay"])    ?$_POST["ngay_quay"]                :"";
        
        $arr_nhi    = explode(";",$giai_nhi);       
        $arr_prov   = explode(";",$province_id);
        //var_dump($arr_prov);die;
        for($i=0;$i<count($arr_prov);$i++){
            if(isset($arr_nhi[$i])){
                $row = AdminKqMientrung::getRowByDateAndProvince($arr_prov[$i],$ngay_quay);
                if(!$row){               
                    $last_id = AdminKqMientrung::insertGiaiNhi($arr_prov[$i],$arr_nhi[$i],$ngay_quay,$user);                  
                }else{
                    $result = AdminKqMientrung::updateGiaiNhi($row["id"],$arr_nhi[$i],$user);
                    //echo $result;die;
                    $last_id = $row["id"];
                }
                $row_update = AdminKqMientrung::getRowById($last_id);
                /*$this->setCacheMienTrung($row_update);*/
                /*$boso1 = isset($arr_nhi[$i]) && $arr_nhi[$i] !="" ? substr($arr_nhi[$i],strlen($arr_nhi[$i])-2,2):"";               

                if($boso1 !=0 && $boso1 !=""){            

                $last_boso_id = AdminKqMientrung::insertThongke($last_id,$boso1,$ngay_quay,"G2",$user);

                }*/
            }

        } 
        if($last_id !=0){
            echo 1;
        }else{
            echo 0;
        }
    }

    public function actionSaveGiaiNhatMientrung(){

        $last_id = 0;
        //echo '11111';die;
        $user = Yii::app()->user->name;
        $giai_nhat      = isset($_POST["giai_nhat"])        ?rtrim($_POST["giai_nhat"],";")     :"";
        $province_id    = isset($_POST["province_id"])      ?rtrim($_POST["province_id"],";")   :"";
        $ngay_quay      = isset($_POST["ngay_quay"])        ?$_POST["ngay_quay"]                :"";

        $arr_nhat = explode(";",$giai_nhat);       
        $arr_prov = explode(";",$province_id);
        //var_dump($arr_prov);die;
        for($i=0;$i<count($arr_prov);$i++){
            if( isset($arr_nhat[$i])){
                $row = AdminKqMientrung::getRowByDateAndProvince($arr_prov[$i],$ngay_quay);
                if(!$row){               
                    $last_id = AdminKqMientrung::insertGiaiNhat($arr_prov[$i],$arr_nhat[$i],$ngay_quay,$user);                  
                }else{
                    $result = AdminKqMientrung::updateGiaiNhat($row["id"],$arr_nhat[$i],$user);
                    //echo $result;die;
                    $last_id = $row["id"];
                }
                $row_update = AdminKqMientrung::getRowById($last_id);
                /*$this->setCacheMienTrung($row_update); */
                /*$boso1 = isset($arr_nhat[$i]) && $arr_nhat[$i] !="" ? substr($arr_nhat[$i],strlen($arr_nhat[$i])-2,2):"";               

                if($boso1 !=0 && $boso1 !=""){            

                $last_boso_id = AdminKqMientrung::insertThongke($last_id,$boso1,$ngay_quay,"G1",$user);

                } */
            }

        } 
        if($last_id !=0){
            echo 1;
        }else{
            echo 0;
        }
    }

    public function actionSaveGiaiDacbietMientrung(){

        $last_id = 0;
        //echo '11111';die;
        $user = Yii::app()->user->name;
         $giai_dacbiet   = isset($_POST["giai_dacbiet"])     ?rtrim($_POST["giai_dacbiet"],";")      :"";
        $province_id    = isset($_POST["province_id"])      ?rtrim($_POST["province_id"],";")       :"";
        $ngay_quay      = isset($_POST["ngay_quay"])        ?$_POST["ngay_quay"]                    :"";

        $arr_dacbiet    = explode(";",$giai_dacbiet);       
        $arr_prov       = explode(";",$province_id);
        //var_dump($arr_prov);die;
        for($i=0;$i<count($arr_prov);$i++){
            if( isset($arr_dacbiet[$i])){
                $row = AdminKqMientrung::getRowByDateAndProvince($arr_prov[$i],$ngay_quay);
                if(!$row){               
                    $last_id = AdminKqMientrung::insertGiaiDacbiet($arr_prov[$i],$arr_dacbiet[$i],$ngay_quay,$user);                  
                }else{
                    $result = AdminKqMientrung::updateGiaiDacbiet($row["id"],$arr_dacbiet[$i],$user);
                    //echo $result;die;
                    $last_id = $row["id"];
                }
                $row_update = AdminKqMientrung::getRowById($last_id);
                /*$this->setCacheMienTrung($row_update);*/
                /*$boso1 = isset($arr_dacbiet[$i]) && $arr_dacbiet[$i] !="" ? substr($arr_dacbiet[$i],strlen($arr_dacbiet[$i])-2,2):"";               

                if($boso1 !=0 && $boso1 !=""){            

                $last_boso_id = AdminKqMientrung::insertThongke($last_id,$boso1,$ngay_quay,"GDB",$user);

                }*/
            }

        } 
        if($last_id !=0){
            echo 1;
        }else{
            echo 0;
        }
    }
    
    
    public function setCacheMienBac($row){      
        $arr_mienbac = array(
        "giai_bay_1" => $row["giai_bay_1"],"giai_bay_2" => $row["giai_bay_2"],"giai_bay_3" => $row["giai_bay_3"],"giai_bay_4" => $row["giai_bay_4"],
        "giai_sau_1" => $row["giai_sau_1"],"giai_sau_2" => $row["giai_sau_2"],"giai_sau_3" => $row["giai_sau_3"],
        "giai_nam_1" => $row["giai_nam_1"],"giai_nam_2" => $row["giai_nam_2"],"giai_nam_3" => $row["giai_nam_3"],"giai_nam_4" => $row["giai_nam_4"],"giai_nam_5" => $row["giai_nam_5"],"giai_nam_6" => $row["giai_nam_6"],
        "giai_tu_1" => $row["giai_tu_1"],"giai_tu_2" => $row["giai_tu_2"],"giai_tu_3" => $row["giai_tu_3"],"giai_tu_4" => $row["giai_tu_4"],
        "giai_ba_1" => $row["giai_ba_1"],"giai_ba_2" => $row["giai_ba_2"],"giai_ba_3" => $row["giai_ba_3"],"giai_ba_4" => $row["giai_ba_4"],"giai_ba_5" => $row["giai_ba_5"],"giai_ba_6" => $row["giai_ba_6"],
        "giai_nhi_1" => $row["giai_nhi_1"],"giai_nhi_2" => $row["giai_nhi_2"],
        "giai_nhat" => $row["giai_nhat"],
        "giai_dacbiet" => $row["giai_dacbiet"] 
        );
      
        $key = "Service.veso.ketquamienbac.giai";
        $cache = Yii::app()->cache->getMemCache()->set($key,$arr_mienbac,3600);
        //Yii::app()->cache->getMem->set();
        //$memcache->set($key,$arr_mienbac,false,3600);
    }
    
    public function setCacheMienNam($row){
        $arr_miennam = array(
        "giai_tam" => $row["giai_tam"],"giai_bay" => $row["giai_bay"],
        "giai_sau_1" => $row["giai_sau_1"],"giai_sau_2" => $row["giai_sau_2"],"giai_sau_3" => $row["giai_sau_3"],
        "giai_nam" => $row["giai_nam"],
        "giai_tu_1" => $row["giai_tu_1"],"giai_tu_2" => $row["giai_tu_2"],"giai_tu_3" => $row["giai_tu_3"],
        "giai_tu_4" => $row["giai_tu_4"],"giai_tu_5" => $row["giai_tu_5"],
        "giai_tu_6" => $row["giai_tu_6"],"giai_tu_7" => $row["giai_tu_7"],
        "giai_ba_1" => $row["giai_ba_1"],"giai_ba_2" => $row["giai_ba_2"],
        "giai_nhi" => $row["giai_nhi"],"giai_nhat" => $row["giai_nhat"],
        "giai_dacbiet" => $row["giai_dacbiet"],"province_id"=>$row["province_id"] 
        );
       
        $key = "Service.veso.ketquamiennam.tinh".$row["province_id"].".giai";
        $cache = Yii::app()->cache->getMemCache()->set($key,$arr_miennam,3600);
        //$memcache->set($key,$arr_miennam,false,3600);
    }
    
    public function setCacheMienTrung($row){
        $arr_mientrung = array(
        "giai_tam" => $row["giai_tam"],"giai_bay" => $row["giai_bay"],
        "giai_sau_1" => $row["giai_sau_1"],"giai_sau_2" => $row["giai_sau_2"],"giai_sau_3" => $row["giai_sau_3"],
        "giai_nam" => $row["giai_nam"],
        "giai_tu_1" => $row["giai_tu_1"],"giai_tu_2" => $row["giai_tu_2"],"giai_tu_3" => $row["giai_tu_3"],
        "giai_tu_4" => $row["giai_tu_4"],"giai_tu_5" => $row["giai_tu_5"],
        "giai_tu_6" => $row["giai_tu_6"],"giai_tu_7" => $row["giai_tu_7"],
        "giai_ba_1" => $row["giai_ba_1"],"giai_ba_2" => $row["giai_ba_2"],
        "giai_nhi" => $row["giai_nhi"],"giai_nhat" => $row["giai_nhat"],
        "giai_dacbiet" => $row["giai_dacbiet"],"province_id"=>$row["province_id"] 
        );
       
        $key = "Service.veso.ketquamientrung.tinh".$row["province_id"].".giai";
        $cache = Yii::app()->cache->getMemCache()->set($key,$arr_mientrung,3600);
        //$memcache->set($key,$arr_mientrung,false,3600);
    }

    public function actionDientoan123(){
        $row = array();
        $date = date("Y-m-d",time());
        $row = AdminDientoan123::getRowByDate($date);
        $this->render("dientoan123",array("row"=>$row));
    }

    public function actionSaveDientoan123(){
        $last_id = 0;
        $user = Yii::app()->user->name;
        $label = isset($_POST["label"])?$_POST["label"]:"";
        $ketqua = isset($_POST["ketqua"])?$_POST["ketqua"]:"";
        $ngay_quay = isset($_POST["ngay_quay"])?$_POST["ngay_quay"]:"";
        $arr_ngay = explode("/",$ngay_quay);        
        if(count($arr_ngay >2)){
            $ngay_quay = $arr_ngay[2]."-".$arr_ngay[1]."-".$arr_ngay[0];
        }else{
            $ngay_quay = date("Y-m-d",time());
        }
        $row = AdminDientoan123::getIdByDate($ngay_quay);
        if(!$row){
            $last_id = AdminDientoan123::insertRow($ngay_quay,$label,$ketqua,$user);
        }else{
            $result = AdminDientoan123::updateRow($row["id"],$label,$ketqua,$user);
            $last_id = $row["id"];
        }

        if($last_id !=0){
            echo 1;
        }else{
            echo 0;
        }
    }

    public function actionThantai(){
        $row = array();
        $date = date("Y-m-d",time());
        $row = AdminThantai::getRowByDate($date);
        $this->render("thantai",array("row"=>$row));
    }

    public function actionSaveThantai(){
        $last_id = 0;
        $user = Yii::app()->user->name;
        $label = isset($_POST["label"])?$_POST["label"]:"";
        $ketqua = isset($_POST["ketqua"])?$_POST["ketqua"]:"";
        $ngay_quay = isset($_POST["ngay_quay"])?$_POST["ngay_quay"]:"";
        $arr_ngay = explode("/",$ngay_quay);        
        if(count($arr_ngay >2)){
            $ngay_quay = $arr_ngay[2]."-".$arr_ngay[1]."-".$arr_ngay[0];
        }else{
            $ngay_quay = date("Y-m-d",time());
        }
        $row = AdminThantai::getIdByDate($ngay_quay);
        if(!$row){
            $last_id = AdminThantai::insertRow($ngay_quay,$label,$ketqua,$user);
        }else{
            $result = AdminThantai::updateRow($row["id"],$label,$ketqua,$user);
            $last_id = $row["id"];
        }

        if($last_id !=0){
            echo 1;
        }else{
            echo 0;
        }
    }

    public function actionDientoan6x36(){
        $row = array();
        $date = date("Y-m-d",time());
        $row = AdminDientoan6x36::getRowByDate($date);
        $this->render("dientoan6x36",array("row"=>$row));
    }

    public function actionSaveDientoan6x36(){
        $last_id = 0;
        $user = Yii::app()->user->name;
        $label = isset($_POST["label"])?$_POST["label"]:"";
        $ketqua = isset($_POST["ketqua"])?$_POST["ketqua"]:"";
        $ngay_quay = isset($_POST["ngay_quay"])?$_POST["ngay_quay"]:"";
        $arr_ngay = explode("/",$ngay_quay);        
        if(count($arr_ngay >2)){
            $ngay_quay = $arr_ngay[2]."-".$arr_ngay[1]."-".$arr_ngay[0];
        }else{
            $ngay_quay = date("Y-m-d",time());
        }
        $row = AdminDientoan6x36::getIdByDate($ngay_quay);
        if(!$row){
            $last_id = AdminDientoan6x36::insertRow($ngay_quay,$label,$ketqua,$user);
        }else{
            $result = AdminDientoan6x36::updateRow($row["id"],$label,$ketqua,$user);
            $last_id = $row["id"];
        }

        if($last_id !=0){
            echo 1;
        }else{
            echo 0;
        }
    }
    
}
